package com.sailfish.springbootdemo.dao.db2;

import com.sailfish.springbootdemo.common.DB2TableName;
import com.sailfish.springbootdemo.pojo.db2.AxiConfig;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface AxiConfigDao {
    @Results(id = "axiConfigResultMap", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "attr_name", property = "attrName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "attr_value", property = "attrValue", jdbcType = JdbcType.VARCHAR),
            @Result(column = "attr_desc", property = "attrDesc", jdbcType = JdbcType.VARCHAR),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_user", property = "createUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "update_user", property = "updateUser", jdbcType = JdbcType.VARCHAR),
    })
    @Select("<script> " +
            "select * " +
            "from " + DB2TableName.AXI_CONFIG +
            "<where> " +
            "<if test='attrName != null and attrName != \"\"'>" +
            " and attr_name = #{attrName}" +
            "</if>" +
            "<if test='status != null'>" +
            " and status = #{status}" +
            "</if>" +
            "</where> " +
            "</script>")
    AxiConfig getByAttrName(@Param("attrName") String attrName, @Param("status") Integer status);

    @Select("<script> " +
            "select * " +
            "from " + DB2TableName.AXI_CONFIG +
            "<where> " +
            "<if test='attrName != null and attrName != \"\"'>" +
            " and attr_name = #{attrName}" +
            "</if>" +
            "<if test='status != null'>" +
            " and status = #{status}" +
            "</if>" +
            "</where> " +
            "</script>")
    @ResultMap(value = "axiConfigResultMap")
    List<AxiConfig> getListByLimit(@Param("attrName") String attrName, @Param("status") Integer status);

    @Insert("<script> " +
            "insert into tb_axi_config(attr_name, attr_value, attr_desc, remark, create_time, create_user, update_time, update_user, status) " +
            "values (#{attrName}, #{attrValue}, #{attrDesc}, #{remark}, #{createTime}, #{createUser}, #{updateTime}, #{updateUser}, #{status})" +
            "</script>")
    Integer insert(AxiConfig axiConfig);

    @Update("<script> " +
            "update " + DB2TableName.AXI_CONFIG +
            "<set> " +
            "<if test='attrValue != null and attrValue != \"\"'>" +
            " attr_value = #{attrValue}," +
            "</if>" +
            "<if test='attrDesc != null and attrDesc != \"\"'>" +
            " attr_desc = #{attrDesc}," +
            "</if>" +
            "<if test='remark != null and remark != \"\"'>" +
            " remark = #{remark}," +
            "</if>" +
            "<if test='updateTime != null'>" +
            " update_time = #{updateTime}," +
            "</if>" +
            "</set> " +
            "where id = #{id}" +
            "</script>")
    Integer update(AxiConfig axiConfig);

    @Delete("<script> " +
            "delete from " + DB2TableName.AXI_CONFIG +
            " where 1 = 1" +
            " and attr_name like CONCAT('%',#{paramValue},'%')" +
            "</script>")
    Integer deleteByAttrName(@Param("paramValue")String paramValue);
}
